export default {
  state: {
	  
    //登录状态
    loginStatus: false,
    //用户信息：头像|昵称...
    userInfo: {},

  },
  getters: {},
  mutations: {
    //一进入项目，就执行该方法： 检测用户是否是登录状态
    initUser(state) {
      let userInfo = uni.getStorageSync('userInfo');
      if (userInfo) {
	    userInfo = JSON.parse(uni.getStorageSync('userInfo'))
        state.loginStatus = true;
        state.userInfo = userInfo;
      } else{
		  console.log('用户未登录')
	  }
    },
    login(state, user) {
      state.loginStatus = true;
      state.userInfo = user;
      //持久化存储==》本地存储
      uni.setStorageSync('userInfo', JSON.stringify(user));
    },
    //退出登录
    loginOut(state) {
      state.loginStatus = false;
      state.userInfo = {};
      uni.removeStorageSync('userInfo');

    }
  },
  actions: {},
};
